package io.zhiller.ollamaclient.ui.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBackIosNew
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import io.zhiller.ollamaclient.ui.navigation.NavActions

@Composable
fun BasicPageLayout(
  modifier: Modifier = Modifier,
  title: String,
  navController: NavController,
  content: @Composable () -> Unit
) {
  Surface(
    modifier = modifier.fillMaxSize()
  ) {
    Column(
      modifier = Modifier
        .fillMaxSize()
        .windowInsetsPadding(WindowInsets.statusBars),
      verticalArrangement = Arrangement.spacedBy(16.dp)
    ) {
      Row(
        verticalAlignment = Alignment.CenterVertically,
      ) {
        IconButton(onClick = { NavActions(navController).back() }) {
          Icon(
            imageVector = Icons.Default.ArrowBackIosNew,
            contentDescription = "返回",
          )
        }
        Text(
          text = title,
          modifier = Modifier.padding(start = 4.dp),
          style = MaterialTheme.typography.headlineSmall
        )
      }
      Surface {
        content()
      }
    }
  }
}